package com.cheyun.netsalev3.view

import android.content.Intent
import android.text.Editable
import android.text.InputType
import android.text.TextUtils
import android.text.TextWatcher
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProviders
import com.bumptech.glide.Glide
import com.cheyun.netsalev3.R
import com.cheyun.netsalev3.databinding.ActivityRegisterBinding
import com.cheyun.netsalev3.databinding.ActivityUserSettingBinding
import com.cheyun.netsalev3.utils.BaseActivity
import com.cheyun.netsalev3.utils.GlideRoundTransform
import com.cheyun.netsalev3.viewmodel.RegisterActivityViewModel
import com.cheyun.netsalev3.viewmodel.UserSettingActivityViewModel
import com.jeremyliao.liveeventbus.LiveEventBus

class UserSettingActivity : BaseActivity<ActivityUserSettingBinding>() {
    override fun initContentView(): Int {
        return R.layout.activity_user_setting
    }

    override fun initViewModel(): ViewModel? {
        return ViewModelProviders.of(this).get(UserSettingActivityViewModel::class.java)
    }

    override fun initData() {
        binding.viewModel?.headimg?.observe(this, Observer {
            Glide.with(this)
                    .load(it)
                    .transform(GlideRoundTransform(this, 5))
                    .placeholder(R.drawable.datuchicun)
                    .error(R.drawable.datuchicun)
                    .into(binding?.ivHead!!)
        })

    }

    override fun initView() {
        binding.radioBut.setOnCheckedChangeListener { group, checkedId ->
            when (checkedId) {
                R.id.nanBut -> binding.viewModel?.setUserSex(1)
                R.id.nvBut -> binding.viewModel?.setUserSex(2)
                R.id.nullBut -> binding.viewModel?.setUserSex(0)
            }
        }
        LiveEventBus.get()
                .with("uploadOrderImg", String::class.java)
                .observe(this, Observer {
                    if (!TextUtils.isEmpty(it)) {
                        binding.viewModel?.setFace(it)
                    }
                })
    }
}
